<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-08-22 11:06:08
 * @LastEditTime: 2020-02-24 09:39:51
 * @LastEditors: Please set LastEditors
 -->
<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport"
			content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<title>Hello APP</title>
		<link rel="stylesheet" type="text/css" href="../css/vant.css">
		<link rel="stylesheet" type="text/css" href="../css/base.css" />
		<link rel="stylesheet" type="text/css" href="../css/local.css" />
		<script type="text/javascript" src="../script/jquery.js"></script>
		<script type="text/javascript" src="../script/layer/mobile/layer.js"></script>
		<script type="text/javascript" src="../script/vue.min.js"></script>
		<script src="../script/vant.min.js"></script>
		<script type="text/javascript" src="../script/fastclick.js"></script>
		<script type="text/javascript" src="../script/base.js"></script>
		<style type="text/css">
			.van-cell__value {
				text-align: right;
			}
		</style>
	</head>

	<body>
		<div id="app" v-cloak>
			<div class="init-full">
				<van-nav-bar class="head" title="修改密码" left-arrow @click-left="onClickLeft">
				</van-nav-bar>
				<div class="body-no-bottom">
					<div class="content">
						<van-field v-model="old_password" type="password" label="旧密码" placeholder="请输入旧密码"></van-field>
						<van-field v-model="new_password1" type="password" label="新密码" placeholder="请输入新密码"></van-field>
						<van-field v-model="new_password2" type="password" label="确认新密码"
							placeholder="请确认新密码"></van-field>
						<div class="btn-padding">
							<van-button :disabled="ifConfirm" :loading="ifConfirm" loading-text="数据提交中..."
								type="primary" block @click="submitConfirm">确认修改</van-button>
						</div>
					</div>
					<van-loading v-if="showLoading" />
				</div>
			</div>
		</div>
	</body>

	<!-- 调用 uniapp webview 的 api ，记得需要写在 body 标签下面 -->
	<script src="../../../assets/script/uni.webview.1.5.4.js"></script>
	<script type="text/javascript">
		var vm;
		//$('.init-full').show();
		var userInfo = FLD.getUserInfo();
		vm = new Vue({
			el: '#app',
			data: {
				showLoading: false,
				ifConfirm: false,
				old_password: '',
				new_password1: '',
				new_password2: '',
			},
			created: function() {
				var that = this;
			},
			methods: {
				submitConfirm() {
					var that = this;
					if (!that.old_password) {
						layer.open({
							content: '请填写原密码!',
							skin: 'msg',
							time: 2
						});
						return false;
					}
					if (!that.new_password1) {
						layer.open({
							content: '请填写新密码!',
							skin: 'msg',
							time: 2
						});
						return false;
					}
					if (that.new_password1 != that.new_password2) {
						layer.open({
							content: '两次输入的密码不一致!',
							skin: 'msg',
							time: 2
						});
						return false;
					}
					that.ifConfirm = true;
					var obj = {
						userId: FLD.getUserInfo().UserId,
						oldPwd: that.old_password,
						newPwd: that.new_password1
					}
					FLD.shoppingMallAjax('UpdatePwd', obj, function(res) {
						that.ifConfirm = false;
						var data = JSON.parse(res);
						if (data.status == 200) {
							window.localStorage.removeItem('userInfo');
							
							layer.open({
								content: '密码修改成功,请重新登录!',
								skin: 'msg',
								time: 2,
								end: function() {
									api.closeWin();
								}
							});

						} else {
							layer.open({
								content: data.msg,
								skin: 'msg',
								time: 2
							});
						}
					})

				},
				onClickLeft() {
					uni.navigateBack()
				}
			}
		})
	</script>

</html>